var Adv_skd=require("./Adv_skd")
var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s,
    c,
    l = e("Util"),
    d = e("GameData"),
    u = e("TaskData");
((c = s || (s = {})).EveryDayTask = "每日任务"), (c.AchieveTask = "成就任务");
var p = cc._decorator,
    h = p.ccclass,
    f =
        (p.property,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (
                    (t.content = null),
                    (t._selectType = s.EveryDayTask),
                    (t.btn_EveryDay = null),
                    (t.btn_Achieve = null),
                    (t.sprite_UI_NoSelect = null),
                    (t.sprite_UI_Select = null),
                    (t.EveryDayScrollView = null),
                    (t.AchieveScrollView = null),
                    t
                );
            }
            return (
                a(t, e),
                (t.prototype.onResetView = function () {
                    e.prototype.onResetView.call(this), this.init();
                    Adv_skd.default.instance.hideAllAdv();
                    Adv_skd.default.instance.showGridAdRight();
                    Adv_skd.default.instance.showInterstitialAd();

                }),
                (t.prototype.onClickClose = function () {
                    Adv_skd.default.instance.hideAllAdv();

                    Adv_skd.default.instance.showGridAdLeftOne();
                    Adv_skd.default.instance.showGridAdRightOne();
                    Adv_skd.default.instance.showInterstitialAd();

                    game.AudioManager.playBtnEffect(), this.closeView(!0);
                }),
                (t.prototype.onDisable = function () { }),
                (t.prototype.onEnable = function () {
                    cc.SDK.showGetUICoinBox(
                        function (e) {
                            var t = d.default.instance.getPlayerCoin();
                            d.default.instance.setPlayerCoin(t + e);
                        },
                        function () { },
                        cc.SDK.gameID
                    );
                }),
                (t.prototype.registerMediator = function () {
                    e.prototype.registerMediator.call(this);
                }),
                (t.prototype.removeMediator = function () {
                    e.prototype.removeMediator.call(this);
                }),
                (t.prototype.addEvent = function () {
                    var t = this;
                    e.prototype.addEvent.call(this),
                        this.btn_EveryDay.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_EveryDay, this),
                        this.btn_Achieve.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_Achieve, this),
                        this.EveryDayScrollView.content.children.forEach(function (e, o) {
                            (e.getChildByName("btn_click").item_index = o),
                                e
                                    .getChildByName("btn_click")
                                    .on(game.EngineEventType.NodeEvent.click, t.onClick_itemClick, t);
                        });
                }),
                (t.prototype.removeEvent = function () {
                    var t = this;
                    e.prototype.removeEvent.call(this),
                        this.btn_EveryDay.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_EveryDay, this),
                        this.btn_Achieve.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_Achieve, this),
                        this.EveryDayScrollView.content.children.forEach(function (e) {
                            e.getChildByName("btn_click").off(
                                game.EngineEventType.NodeEvent.click,
                                t.onClick_itemClick,
                                t
                            );
                        });
                }),
                (t.prototype.onClick_btn_EveryDay = function () {
                    game.AudioManager.playBtnEffect(),
                        this._selectType != s.EveryDayTask &&
                            ((this._selectType = s.EveryDayTask), this.update_btnType());
                }),
                (t.prototype.onClick_btn_Achieve = function () {
                    game.AudioManager.playBtnEffect(),
                        this._selectType != s.AchieveTask &&
                            ((this._selectType = s.AchieveTask), this.update_btnType());
                }),
                (t.prototype.update_btnType = function () {
                    this._selectType == s.EveryDayTask
                        ? ((this.btn_EveryDay.getComponent(cc.Sprite).spriteFrame = this.sprite_UI_Select),
                          (this.btn_Achieve.getComponent(cc.Sprite).spriteFrame = this.sprite_UI_NoSelect))
                        : ((this.btn_EveryDay.getComponent(cc.Sprite).spriteFrame = this.sprite_UI_NoSelect),
                          (this.btn_Achieve.getComponent(cc.Sprite).spriteFrame = this.sprite_UI_Select)),
                        (this.EveryDayScrollView.node.active = this._selectType == s.EveryDayTask),
                        (this.AchieveScrollView.node.active = this._selectType == s.AchieveTask);
                }),
                (t.prototype.init = function () {
                    (this.isCache = !1),
                        (this.content = this.node.getChildByName("content")),
                        (this.btn_EveryDay = this.content.getChildByName("btn_EveryDay")),
                        (this.btn_Achieve = this.content.getChildByName("btn_Achieve")),
                        (this.sprite_UI_NoSelect = this.btn_Achieve.getComponent(cc.Sprite).spriteFrame),
                        (this.sprite_UI_Select = this.btn_EveryDay.getComponent(cc.Sprite).spriteFrame),
                        (this.EveryDayScrollView = this.content
                            .getChildByName("scrollViews")
                            .getChildByName("EveryDayScrollView")
                            .getComponent(cc.ScrollView)),
                        (this.AchieveScrollView = this.content
                            .getChildByName("scrollViews")
                            .getChildByName("AchieveScrollView")
                            .getComponent(cc.ScrollView)),
                        this.initScrollViews(),
                        this.update_btnType();
                }),
                (t.prototype.initScrollViews = function () {
                    for (
                        var e = u.default.instance.task_list_index,
                            t = u.default.instance.task_coin,
                            o = this.EveryDayScrollView.content.children[0],
                            n = 0;
                        n < e.length;
                        n++
                    ) {
                        var i = e[n],
                            a = void 0;
                        ((a = 0 == i ? o : cc.instantiate(o)).parent = this.EveryDayScrollView.content),
                            (a.y = -n * o.height),
                            (a.getChildByName("task_index").getComponent(cc.Label).string = n + 1 + ""),
                            (a.getChildByName("task_name").getComponent(cc.Label).string =
                                u.default.instance.task_list[i]),
                            (a.getChildByName("item_bg2").active = i % 2 == 0),
                            (a.getChildByName("item_bg").active = i % 2 == 1),
                            (a
                                .getChildByName("btn_click")
                                .getChildByName("label_reward")
                                .getComponent(cc.Label).string = "钻石+" + t[i]);
                        var r = a.getChildByName("task_progressBar").getComponent(cc.ProgressBar);
                        (a.target_index = i), (r.progress = u.default.instance.getTaskProgressByIndex(i));
                    }
                    (this.EveryDayScrollView.content.height = e.length * o.height), this.refresh_EveryDayScrollView();
                }),
                (t.prototype.refresh_EveryDayScrollView = function () {
                    this.EveryDayScrollView.content.children.forEach(function (e) {
                        e.getChildByName("btn_click").active =
                            "false" == l.default.getItem(e.target_index + "task" + l.default.getTodayStr(), "false");
                    });
                }),
                (t.prototype.onClick_itemClick = function (e) {
                    if (
                        (game.AudioManager.playBtnEffect(),
                        1 == e.node.parent.getChildByName("task_progressBar").getComponent(cc.ProgressBar).progress)
                    ) {
                        var t = d.default.instance.getPlayerCoin();
                        d.default.instance.setPlayerCoin(t + u.default.instance.task_coin[e.node.item_index]),
                            l.default.setItem(e.node.parent.target_index + "task" + l.default.getTodayStr(), "true"),
                            this.refresh_EveryDayScrollView(),
                            game.UIManager.instance.showToast("钻石已领取");
                    } else game.UIManager.instance.showToast("任务未完成");
                }),
                r([h], t)
            );
        })(game.BasePopView));
i.default = f;
